<%@page import="qingke.mybatis.pojo.Product"%>
<%@page import="java.util.List"%>
<%@page import="qingke.util.Const"%>
<%@page import="qingke.bean.Page"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>店铺</title>
<link href="${pageContext.request.contextPath }/css/news.css"
	type="text/css" rel="stylesheet" />
<script src="${pageContext.request.contextPath }/js/jquery-1.8.3.min.js"></script>
<script src="${pageContext.request.contextPath }/js/menu.js"></script>
<jsp:include page="top.jsp"></jsp:include>
</head>
<%
	String select = request.getParameter("select");
	if (select != null) {
		session.setAttribute("select", select);
	} else {
		session.removeAttribute("select");
	}
%>
<%
	List<Product> products = null;
	Object productsObject = session.getAttribute("products");
	if (productsObject != null) {
		if (productsObject instanceof List) {
			products = (List<Product>) productsObject;
		}
	}
%>
<%
	Page productPage = null;
	Object productPageObject = session.getAttribute("productPage");
	if (productPageObject != null) {
		if (productPageObject instanceof Page) {
			productPage = (Page) productPageObject;
		}
	}
%>
<body>
	<br />
	<!--内容-->
	<div class="main">
		<div class="mainl">
			<div class="mainl-s">
				<ul>
					<li><a href="#" class="bg">商品索引<br />
					</a></li>
				</ul>
			</div>
			<div class="mainl-c">
				<ul>
					<li><a href="#"><br /> <span></span></a></li>
				</ul>
			</div>

		</div>
		<div class="mainr">
			<div class="mainr-s">
				<div class="mainr-sl pr">
					<p>
						商品中心<br /> <span>PRODUCT CENTER</span>
					</p>
				</div>
				<div class="mainr-sr">
					<a href="#">当前位置</a> ><a href="#"> 首页</a> ><a href="#"> 商品中心</a>

				</div>

			</div>
			<div class="mainr-tu">
				<ul>
					<%
						if (products != null) {
							for (Product product : products) {
					%>
					<li><a href="dianpu2.html"><img src="images/chan03.png" /></a>
						<p>
							<a href="dianpu2.html"><%=product.getProductName()%></a>
							<button onclick="addToCart(<%=product.getId()%>)">加入购物车</button>
						</p></li>
					<%
						}
						}
					%>
				</ul>

			</div>
			<div class="mainr-pg">
				<ul>
					<%
						if (productPage != null) {
							double displayPageDOUBLE = (double) productPage.getCurrentPage() / (double) Const.PAGE_PRODUCT_NUMBER;
							int displayPage = (int) Math.ceil(displayPageDOUBLE);
							double dispalyPageAllDOUBLE = (double) productPage.getTotalPage() / (double) Const.PAGE_PRODUCT_NUMBER;
							int displayPageAll = (int) Math.ceil(dispalyPageAllDOUBLE);
							if (productPage.getCurrentPage() != 1) {
					%>
					<li><a role="button"
						href="Product/getProductAjax?NumberOfPage=<%=1%>">首页</a></li>
					<li><a role="button"
						href="Product/getProductAjax?NumberOfPage=<%=productPage.getCurrentPage() - 1%>">上一页</a></li>
					<%
						}
					%>
					<%
						if (productPage.getTotalPage() >= Const.PAGE_PRODUCT_NUMBER) {
								for (int i = (displayPage - 1) * Const.PAGE_PRODUCT_NUMBER
										+ 1; i <= (displayPage * Const.PAGE_PRODUCT_NUMBER < productPage.getTotalPage()
												? displayPage * Const.PAGE_PRODUCT_NUMBER
												: productPage.getTotalPage()); i++) {
									if (i == productPage.getCurrentPage()) {
					%>
					<li><a role="button" href="javascript:volid(0)" href="#"
						disabled="disabled" style="color: #c0c0c0"><%=i%></a></li>
					<%
						} else {
					%>
					<li><a role="button"
						href="Product/getProductAjax?NumberOfPage=<%=i%>"><%=i%></a></li>
					<%
						}
								}
							} else {
								for (int i = 1; i < productPage.getTotalPage() + 1; i++) {
									if (i == productPage.getCurrentPage()) {
					%>
					<li><a role="button" href="javascript:volid(0)" href="#"
						disabled="disabled" style="color: #c0c0c0"><%=i%></a></li>
					<%
						} else {
					%>
					<li><a role="button"
						href="Product/getProductAjax?NumberOfPage=<%=i%>"><%=i%></a></li>
					<%
						}
								}
							}
					%>
					<%
						if (productPage.getCurrentPage() != productPage.getTotalPage()) {
					%>
					<li><a role="button"
						href="Product/getProductAjax?NumberOfPage=<%=productPage.getCurrentPage() + 1%>">下一页</a></li>
					<li><a role="button"
						href="Product/getProductAjax?NumberOfPage=<%=productPage.getTotalPage()%>">尾页</a></li>
					<%
						}
					%>
					<li>共<%=productPage.getTotalPage()%>页
					</li>
					<li>跳转到<input id="yeshutiaozhuan"
						style="width: 30px; margin-left: 5px; margin-right: 5px" />页
						<button role="button" onclick="ToAPage()">跳转</button></li>
					<%
						}
					%>
				</ul>
			</div>
		</div>




	</div>
	<div class="jie">

		<div class="shu">
			<p>联系我们 技术咨询热线: 4000-569-869 Copyright 2011-2014moshi(北京)服装有限公司
				E-mail:info@fuzhuang.com Web:www.mycodes.net</p>
		</div>

	</div>
	<script>
function prevent(e) {
        e.preventDefault ? e.preventDefault() : e.returnValue = false;
    }
    function digitInput(e) {
        var c = e.charCode || e.keyCode; //FF、Chrome IE下获取键盘码
        if ((c != 8 && c != 46 && // 8 - Backspace, 46 - Delete
                (c < 37 || c > 40) && // 37 (38) (39) (40) - Left (Up) (Right) (Down) Arrow
                (c < 48 || c > 57) && // 48~57 - 主键盘上的0~9
                (c < 96 || c > 105)) // 96~105 - 小键盘的0~9
                || e.shiftKey) { // Shift键，对应的code为16
            prevent(e); // 阻止事件传播到keypress
        }
    }
    $(function(){
        $("#yeshutiaozhuan").keydown(function(e) {
            digitInput(e);
        });
});
   function ToAPage(){
	   var NumberOfPage = $("#yeshutiaozhuan").val();
	   window.location.href='Store/getProductAjax?NumberOfPage=' + NumberOfPage;
   }
   
    
</script>
</body>
</html>
